<!--  -->
<template>
  <div class="kkkk">
    <el-form ref="form" :model="sizeForm" size="medium">
      <el-form-item label="发票类型：">
        <el-radio-group v-model="sizeForm.InvoiceType" size="medium">
          <el-radio border label="0">不开发票</el-radio>
          <el-radio border label="1">增值税普通发票</el-radio>
          <el-radio border label="2">增值税专业发票</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="onSubmit(sizeForm)" :loading="loading">生成报价单</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      sizeForm: {
        InvoiceType: "0"
      }
    };
  },
  methods: {
    async onSubmit(sizeForm) {
      this.loading = true;
      let user_id = this.$store.state.user_id; // 用户id
      const list = this.$store.state.QuotationData;
      let param = []; // 商品id
      list.forEach(element => {
        console.log(element);
        param.push({
          goods_id: element.id,
          selling_price: element.selling_price,
          num: element.num
        });
      });
      let invoice_type = sizeForm.InvoiceType; //发票类型
      console.log(user_id, param, invoice_type);
      let res = await this.$http({
        method: "post",
        url: "index/api/createQuote",
        data: {
          user_id,
          param,
          invoice_type
        }
      });
      if (res.data.State.Code == 200) {
        this.$router.push("/myquotation");
        this.loading = false;
      } else {
        this.loading = true;
      }
    }
  }
};
</script>
<style lang='scss' scoped>
.kkkk {
  padding-top: 20px;
  border: 1px solid #f3f3f3;
  margin-bottom: 48px;
  .el-form-item {
    margin-left: 5px;
    .el-radio-group {
      width: 40vw;
      text-align: left;
      .el-radio {
        margin-top: 5px;
        margin-left: 0px !important;
      }
    }
    .el-button {
      margin-left: 100px;
    }
  }
}
</style>